<?php
/**
 */
class MembersTable extends Doctrine_Table
{
     public function checkUniqueRecord($email)
	{
	    //echo $email;exit;
		$query=new Doctrine_Query();
		$query->select('count(m.member_id) as numCount')
			  ->from('Members m')
			  ->where("m.email='".$email."'");
		$result = $query->execute();
		return $result[0];	  
	}
	public function checkUserName($username)
	{
		$query=new Doctrine_Query();
		$query->select('count(m.member_id) as numCount')
			  ->from('Members m')
			  ->where("m.username='".$username."'");
		$result = $query->execute();
		return $result[0];	  
	}
	public function loginCheck($username,$password)
	{
	    //	echo $username." ".$password;exit;
	    $query=new Doctrine_Query();
		$query->select('count(m.member_id) as numCount')
		       ->from('Members m')
			   ->where("m.username='".$username."' and m.password='".$password."'");
			   //echo $query;exit;
			   	$result = $query->execute();
				return $result[0];
				
	}
	public function getUserId($username)
	{
	     $query = new Doctrine_Query();
		$query ->select('m.*')
			   ->from('Members m')
			   ->where("m.username='".$username."'")
			   ->limit(1);
		$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
		return $result[0];
	}

		public function getDetailsById($userId)
	{
	    //	echo $username." ".$password;exit;
	    $query=new Doctrine_Query();
		$query->select('m.*')
		       ->from('Members m')
			   ->where("m.member_id=".$userId);
			   //echo $query;exit;
			   	$result = $query->execute(Doctrine::HYDRATE_ARRAY);
				return $result[0];
				
	}
	public function getMembersByMailId($email)
	{
	    	
	    $query=new Doctrine_Query();
		$query->select('m.*')
		       ->from('Members m')
			   ->where("m.email='".$email."'");
			   //echo $query;exit;
			   	$result = $query->execute(Doctrine::HYDRATE_ARRAY);
				return $result[0];
				
	}
	public function updatePassword($password,$email)
	{
		$query = new Doctrine_Query();
		$query->update('Members')
			  ->set('password',"'".$password."'")
			  ->where("email='".$email."'");
		return $query->execute();	  
	}
	
	public function member_register($first_name,$username,$password,$email)
	{
	      $sql="insert into members(first_name,username,password,email,status,created_time)values('".$first_name."','".$username."','".$password."','".$email."','0','".date('Y-m-d H:i:s')."')";
	      $r=mysql_query($sql);
		  if($r>0)
          {
               return 'yes';
          }
          else
          {
            return '';
          }
	}
	public function addUser($data)
	{
		$csrsvalues = '';
		foreach($data['csr'] as $csrs)
		{
			$csrsvalues.= $csrs.',';
		}
		
		$crssValue = trim($csrsvalues,',');//exit;
		$firstname = ucfirst(addslashes(trim($data['firstname'])));
		$email = ucfirst(addslashes(trim($data['email'])));
		$username = ucfirst(addslashes(trim($data['username'])));
		
		$password = ucfirst(addslashes(trim($data['password'])));
		$terms = addslashes(trim($data['terms']));
				
		$member = new Members();
		$member ->first_name = $firstmane;
		$member ->email = $email;
		$member ->username = $username;
		$member ->password = $password;
		$member ->terms = $terms;
        echo '<pre>';print_r($member);exit;
		$org ->save();
		return $org->org_id;
	}

}